Recommended R packages for plotting :
Learn more:
tmap In an nutshell:
qtm()tm_shape(), tm_fill(), tm_borders(), tm_lines(), tm_layout() etc.tmap_mode('view') and tmap_mode('plot').Some resources on tmap:
library(here)
library(mapview)
library(sf)
library(tmap)
library(dplyr)
library(readxl)
library(scales) # for function percent_format()
# (1) load spatial data
raillines <- st_read(here('data/source/census_1851_raillines/1851EngWalesScotRail_Lines.shp'))
districts_spatial <- st_read(here('data/source/census_1851_districts/1851EngWalesRegistrationDistrict.shp')) %>%
mutate(CEN1 = as.numeric(as.character(CEN1))) # make sure identifiers are the same type
# (2) load and add data-of-interest
districts_data <- read_excel(here('data/census1851_districts_count.xlsx'))
districts <- left_join(districts_spatial, districts_data, by = c('CEN1' = 'district_id'))
tm_shape(districts) +
tm_borders()

tm_shape(districts) +
tm_fill('pct_secondary')

tm_shape(districts) +
tm_borders(col = 'white') +
tm_fill('pct_secondary', title = 'Emploment secondary sector')

tm_shape(districts) +
tm_borders(col = 'white') +
tm_fill('pct_secondary', title = 'Emploment secondary sector') +
tm_shape(raillines) +
tm_lines(col = 'grey60')

nwestern <- districts %>%
filter(R_DIV == 'NORTH WESTERN')
tm_shape(nwestern) +
tm_fill(col = 'pct_secondary') +
tm_text('district_name', size = .5)

map_final <- tm_shape(districts) +
tm_borders(col = 'white') +
tm_fill('pct_secondary', title = 'Secondary sector\nemployment', legend.format = percent_format(accuracy = 1), legend.hist = TRUE) +
tm_shape(raillines) +
tm_lines(col = 'grey60') +
tm_layout(main.title = 'Railways & secondary sector employment in 1851', legend.outside = TRUE, frame = FALSE) +
tm_credits('Source: Cambridge Group for the\nHistory of Population and Social Structure', position = 'right', align = 'right')
map_final

# save final map
tmap_save(map_final, here('output/england_1851_map_final.png'), width = 1920, height = 1920)
## Map saved to /home/rstudio/projects/historical-maps-r/output/england_1851_map_final.png
## Resolution: 1920 by 1920 pixels
## Size: 6.4 by 6.4 inches (300 dpi)
tmap_mode("view")
tm_shape(nwestern) +
tm_fill(col = 'pct_secondary') +
tm_text('district_name')
tmap_mode("plot")
tmap_mode("view")
## tmap mode set to interactive viewing
map_final
## Credits not supported in view mode.
## Warning: The shape districts is invalid. See sf::st_is_valid